package cn.ccit.action;
import java.util.List;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ModelDriven;

import cn.ccit.entites.Dishes;
import cn.ccit.iservers.IDishesServers;
import cn.ccit.model.BaseModel;
import cn.ccit.servers.DishesServers;
/**
 * 
 * ClassName: DishesAction <br/> 
 * Function: 菜品的action发送json与接收参数的类. <br/> 
 * Reason: TODO ADD REASON(可选). <br/> 
 * date: 2016年11月5日 下午3:08:31 <br/> 
 * 
 * @author wanghao 
 * @version 1.0
 * @since JDK 1.6
 */
public class DishesAction extends BaseAction implements ModelDriven<Dishes>{
	/** 
	 * serialVersionUID:TODO(版本号). 
	 * @since JDK 1.6 
	 */   
	private static final long serialVersionUID = 1L;
	private IDishesServers iDishServers=new DishesServers();
	private Dishes dish=new Dishes();
	
	
	@Override
	public String addData() {
		sendJsonData(iDishServers.addDishes(dish), new BaseModel<Dishes>());
		return super.addData();
	}

	@Override
	public String removeData() {
		sendJsonData(iDishServers.removeDishes(dish), new BaseModel<Dishes>());
		return super.removeData();
	}

	@Override
	public String changeDataInfo() {
		sendJsonData(iDishServers.changeDishesInfo(dish),new BaseModel<Dishes>(),dish);
		return super.changeDataInfo();
	}

	@Override
	public String getDataList() {
		sendJsonDataList(iDishServers.getSomeDishes(startId, limit), new BaseModel<List<Dishes>>());
		return super.getDataList();
	}
	
	@Override
	public Dishes getModel() {
		return dish;
	}

	@Override
	public String sreachDataById() {
		Dishes di=iDishServers.searchDishesByID(dish.getId());
		sendJsonData(di!=null, 
				new BaseModel<Dishes>(),
				di);
		return super.sreachDataById();
	}

	@Override
	public String sreachDataByName() {
		Dishes di=iDishServers.searchDishesByName(dish.getName());
		sendJsonData(di!=null, 
				new BaseModel<Dishes>(),
				di);
		return super.sreachDataByName();
	}
	public String sreachDataByShortFor() {
		sendJsonDataList(iDishServers.searchDishesByShortFor(dish.getShortFor()),
				new BaseModel<List<Dishes>>());
		return Action.SUCCESS;
	}
	public String sreachDataByKind() {
		sendJsonDataList(iDishServers.searchDishesByKind(dish.getEnumName()),
				new BaseModel<List<Dishes>>());
		return Action.SUCCESS;
	}
	
}
